home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / TERM_VLA.ZIP / TERM2.ASM < prev    next >
Assembly Source File  |  1993-08-29  |  9KB  |  413 lines

  1.     IDEAL
  2.     DOSSEG
  3.     MODEL SMALL
  4.     STACK 400h
  5.     CODESEG
  6.     p286
  7. ────────────────────────────────────────────────────────────────────────────
  8. INCLUDE "EXEC.INC"
  9. ────────────────────────────────────────────────────────────────────────────
  10. TimeOut     =   364                 ;20 seconds (18.2 * 20)
  11. NormWait    =   18                  ;1 second
  12. BuffSize    =   2048                ;Size of incoming buffer (in bytes)
  13.  
  14. ; The following equates are modem configuration settings
  15. ComInt      =   0bh     ;COM1/COM3=0Ch, COM2/COM4=0Bh
  16. ComAddr     =   2F8h    ;COM1=3F8h, COM2=2F8h, COM3=3E8h, COM4=2E8h
  17.  
  18. BRDMSB      =   0
  19. BRDLSB      =   03h
  20.  
  21. ;BRDMSB = 0 
  22. ;BRDLSB = 1,843,200/(16*baud rate)              
  23. ;
  24. ; 60h = 1200
  25. ; 30h = 2400
  26. ; 0ch = 9600
  27. ; 06h = 19200
  28. ; 03h = 38400
  29. ; 02h = 57600
  30. ; 01h = 115200
  31.  
  32. ; The following equates are for data format settings
  33. DF_N81      =       00000011b           ;8 data bits, 1 stop bit, no parity
  34. DF_E71      =       00011010b           ;7 data bits, 1 stop bit, even parity
  35.  
  36. OldComInt   dd      ?
  37.  
  38. SendCount   dw      0000
  39. CTMax       DW      0000
  40.  
  41. MSG_SetUp   db      'Setting up modem information ...',13,10,0
  42. MSG_NoMem   db      'Could not allocate buffer space',13,10,0
  43. MSG_Exit    db      'Press F-12 to exit program',13,10,13,10,0
  44. MSG_TimeOut db      '!',0
  45.  
  46. BuffSeg     DW      0000
  47. Head        DW      0000
  48. Tail        DW      0000
  49.  
  50. LocalEcho   db  0
  51. ────────────────────────────────────────────────────────────────────────────
  52.     ────────────────────────────────────────────────────────────────────
  53.     ; The following routine hooks in the interrupt routine and sets up 
  54.     ;the data format and communications parameters
  55.     ────────────────────────────────────────────────────────────────────
  56. PROC SetUpComPort NEAR
  57.     pusha
  58.     push    ds es
  59.     mov     ax,cs
  60.     mov     ds,ax
  61.  
  62.     mov     si,offset MSG_SetUp
  63.     call    PrintZ
  64.  
  65.     mov     al,ComInt
  66.     mov     ah,35h
  67.     int     21h
  68.     mov     [WORD LOW  OldComInt],bx
  69.     mov     [WORD HIGH OldComInt],es
  70.  
  71.     mov     al,ComInt
  72.     mov     dx,offset IntHandler    ;ds:dx = new int vector
  73.     mov     ah,25h
  74.     int     21h
  75.  
  76.     cli
  77.     mov     dx,ComAddr+3            ;point to Line Control register
  78.     mov     al,DF_N81
  79.     out     dx,al
  80.     inc     dx                      ;point to modem control register
  81.     mov     al,00001011b            ;set it for interrupts
  82.     out     dx,al
  83.  
  84.     in      al,21h
  85.     and     al,11100111b            ;enable both IRQ's
  86.     out     21h,al
  87.  
  88.     mov     dx,ComAddr+1
  89.     mov     al,00000001b            ;turn on int's
  90.     out     dx,al
  91.     sti
  92.  
  93.     call    SetBaudRate
  94.  
  95.     pop     es ds
  96.     popa
  97.     ret
  98. ENDP
  99.     
  100.     ────────────────────────────────────────────────────────────────────
  101.     ; This one disables the com port and turns off the interrupt
  102.     ────────────────────────────────────────────────────────────────────
  103. PROC TurnOffComPort NEAR
  104.     pusha
  105.  
  106.     mov     dx,ComAddr+1
  107.     mov     al,0            ;disable interrupts
  108.     out     dx,al
  109.  
  110.     in      al,21h
  111.     or      al,00011000b    ;disable com interrupts
  112.     out     21h,al
  113.  
  114.     push    ds
  115.     mov     dx,[WORD LOW  OldComInt]
  116.     mov     ds,[WORD HIGH OldComInt]
  117.     mov     al,ComInt
  118.     mov     ah,25h
  119.     int     21h
  120.     pop     ds
  121.  
  122.     popa
  123.     ret
  124. ENDP
  125.     ────────────────────────────────────────────────────────────────────
  126.     ; Checks the input buffer and displays everything there
  127.     ────────────────────────────────────────────────────────────────────
  128. PROC DisplayBuffer NEAR
  129.     pusha
  130.     push    es
  131.  
  132.     mov     si,[cs:Tail]
  133.     cmp     si,[cs:Head]
  134.     je      @@NoInput
  135.  
  136.     mov     es,[cs:BuffSeg]
  137.     cld
  138. @@PrintLoop:
  139.     mov     dl,[es:si]
  140.     inc     si
  141.     mov     ah,2
  142.     int     21h
  143.     cmp     si,BuffSize
  144.     jne     @@NotAtEnd
  145.     xor     si,si
  146.  
  147. @@NotAtEnd:
  148.     cmp     si,[cs:Head]
  149.     jne     @@PrintLoop
  150.     mov     [cs:Tail],si
  151.  
  152. @@NoInput:
  153.     pop     es
  154.     popa
  155.     ret
  156. ENDP
  157.     ────────────────────────────────────────────────────────────────────
  158.     ; Sends a character across the serial line 
  159.     ;
  160.     ; IN: AL = Char
  161.     ;OUT: CF = 1 if timeout occurred
  162.     ────────────────────────────────────────────────────────────────────
  163. PROC SendChar NEAR
  164.     pusha
  165.     push    ax
  166.     xor     ah,ah
  167.     int     1ah
  168.     mov     [cs:SendCount],dx
  169.  
  170. @@Xloop1:
  171.     mov     dx,ComAddr+5
  172.     in      al,dx
  173.     test    al,00100000b        ;we ready to send?
  174.     jnz     @@XLoop2
  175.  
  176.     mov     bx,[cs:SendCount]
  177.     mov     ax,NormWait
  178.     call    CheckTime
  179.     jnc     @@XLoop1
  180.     pop     ax
  181.     jmp     short @@XBad
  182.  
  183. @@XLoop2:
  184.     pop     ax
  185.     mov     dx,ComAddr
  186.     out     dx,al
  187.  
  188.     clc
  189.     jmp     short @@Exit
  190.  
  191. @@XBad:
  192.     stc
  193. @@Exit:
  194.     popa
  195.     ret
  196. ENDP
  197.     ────────────────────────────────────────────────────────────────────
  198.     ; Routine to check if time has elapsed
  199.     ;
  200.     ; IN: BX = original ticks (for timeout)
  201.     ;     AX = time to wait
  202.     ;
  203.     ;OUT: CF = 1 if time expired
  204.     ────────────────────────────────────────────────────────────────────
  205. PROC CheckTime NEAR    
  206.     pusha
  207.     mov     [cs:CTMax],ax
  208.     mov     ah,0
  209.     int     1ah
  210.     cmp     bx,dx
  211.     jg      short @@Time1   ;check for wrap around
  212.  
  213.     sub     dx,bx
  214.     jmp     short @@Time2
  215.  
  216. @@Time1:
  217.     mov     ax,0ffffh
  218.     sub     ax,bx
  219.     add     dx,ax
  220.  
  221. @@Time2:
  222.     cmp     dx,[cs:CtMax]
  223.     ja      short @@TimeOut
  224.     clc     
  225.     jmp     short @@Exit
  226.  
  227. @@TimeOut:
  228.     stc
  229. @@Exit:
  230.     popa
  231.     ret
  232. ENDP
  233.     ────────────────────────────────────────────────────────────────────
  234.     ; sets BAUD rate
  235.     ────────────────────────────────────────────────────────────────────
  236. PROC SetBaudRate NEAR   
  237.     push    ax dx
  238.  
  239.     mov     dx,ComAddr+3
  240.     in      al,dx
  241.     or      al,10000000b
  242.     out     dx,al
  243.  
  244.     sub     dl,2
  245.     mov     al,BRDMSB       ;set the baud rates
  246.     out     dx,al
  247.  
  248.     dec     dl
  249.     mov     al,BRDLSB
  250.     out     dx,al
  251.  
  252.     add     dl,3
  253.     in      al,dx
  254.     and     al,01111111b    
  255.     out     dx,al
  256.  
  257.     pop     dx ax
  258.     ret
  259. ENDP
  260.  
  261.     ────────────────────────────────────────────────────────────────────
  262.     ; The following routine prints the ASCIIZ string pointed to by DS:SI
  263.     ────────────────────────────────────────────────────────────────────
  264. PROC PrintZ NEAR
  265.     push    ax dx si
  266.  
  267.     mov     ah,2
  268. @@PLoop:
  269.     mov     dl,[si]
  270.     inc     si
  271.     or      dl,dl
  272.     je      short @@Done
  273.     int     21h
  274.     jmp     short @@PLoop
  275.  
  276. @@Done:
  277.     pop     si dx ax
  278.     ret
  279. ENDP
  280.  
  281.     ────────────────────────────────────────────────────────────────────
  282.     ; Interrupt handler - process byte coming in on serial channel (COM)
  283.     ────────────────────────────────────────────────────────────────────
  284. PROC IntHandler FAR
  285.     push    ax dx ds es di
  286.  
  287.     mov     dx,ComAddr+4        ;point to modem control register
  288.     in      al,dx       
  289.     and     al,11111101b        ;turn off RTS
  290.     out     dx,al
  291.  
  292.     mov     ax,cs
  293.     mov     ds,ax
  294.     mov     es,[BuffSeg]
  295.     mov     di,[Head]
  296.     cld
  297.  
  298. @@Recieve:
  299.     mov     dx,ComAddr
  300.     in      al,dx
  301.     stosb
  302.     cmp     di,BuffSize
  303.     jne     @@NoWrap
  304.     xor     di,di
  305.  
  306. @@NoWrap:
  307.     mov     [Head],di
  308.  
  309.     mov     dx,Comaddr+2            ;is another byte ready??
  310.     in      al,dx
  311.     test    al,1        
  312.     jz      @@Recieve
  313.  
  314.     mov     al,20h
  315.     out     20h,al
  316.  
  317.     mov     dx,Comaddr+4        ;turn RTS back on
  318.     in      al,dx
  319.     or      al,00000010b
  320.     out     dx,al
  321.  
  322.     pop     di es ds dx ax
  323.     iret
  324. ENDP
  325. ────────────────────────────────────────────────────────────────────────────
  326. START:
  327.     mov     bx,ss
  328.     mov     ax,es
  329.     sub     bx,ax
  330.     mov     ax,sp
  331.     add     ax,15
  332.     shr     ax,4
  333.     add     bx,ax
  334.     mov     ah,4ah
  335.     int     21h     ;shrink down to minimum
  336.  
  337.     mov     ax,cs
  338.     mov     ds,ax
  339.  
  340.     mov     ah,48h
  341.     mov     bx,BuffSize/16
  342.     int     21h
  343.     jnc     @@MemOK
  344.  
  345.     mov     si,offset MSG_NoMem
  346.     call    PrintZ
  347.     jmp     @@AllDone
  348.  
  349. @@MemOk:
  350.     mov     [BuffSeg],ax
  351.     call    SetUpComPort
  352.  
  353.     mov     si,offset MSG_Exit
  354.     call    PrintZ
  355.  
  356. @@MainLoop:
  357.     mov     ah,11h
  358.     int     16h
  359.     jz      @@NoKey
  360.  
  361.     mov     ah,10h
  362.     int     16h
  363.     cmp     ah,134      ;f12 key?
  364.     je      @@AllDone
  365.  
  366.     cmp     ah,133      ;f11 key? (toggle local echo)
  367.     jne     @@Notoggle
  368.     xor     [LocalEcho],1
  369.     jmp     @@NoKey
  370. @@Notoggle:
  371.     cmp     ah,73 
  372.     jne     @@NoUpload
  373.     call    Upload
  374.     jmp     @@NoKey
  375.  
  376. @@NoUpload:
  377.     cmp     ah,81
  378.     jne     @@NoDownload
  379.     call    Download
  380.     jmp     @@NoKey
  381.  
  382. @@NoDownload:
  383.     cmp     [LocalEcho],0       ;is local echo on?
  384.     je      @@noEcho
  385.  
  386.     push    ax
  387.     mov     ah,2
  388.     mov     dl,al
  389.     int     21h
  390.     pop     ax
  391.  
  392. @@noEcho:
  393.     call    SendChar
  394.     jnc     @@NoKey
  395.  
  396.     mov     si,offset MSG_TimeOut
  397.     call    PrintZ
  398.  
  399. @@NoKey:
  400.     call    DisplayBuffer
  401.     jmp     @@MainLoop
  402.  
  403. @@AllDone:
  404.     call    TurnOffComPort
  405.     mov     es,[Buffseg]
  406.     mov     ah,49h
  407.     int     21h
  408.  
  409.     mov     ax,4c00h
  410.     int     21h
  411. END Start            
  412.  
  413.